﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyMvcStoreApplication.Models;
using System.Data.Entity.Validation;
using MyMvcStoreApplication.Repositories;

namespace MyMvcStoreApplication.Controllers
{
    public class SocialController : Controller
    {
        SocialRepository repository = new SocialRepository();

        //
        // GET: /Social/

        public ActionResult Index()
        {
            this.FillViewBag();

            var albumes = repository.GetAlbumes();
            return View("Index", albumes);
        }

        private void FillViewBag()
        {
            ViewBag.GeneroList = repository.GetGeneros();
        }

        public ActionResult Genero(int id)
        {
            this.FillViewBag();

            var albumes = repository.GetAlbumes(id);
            return View("Index", albumes);
        }

        [HttpPost]
        public int MeGusta(int id)
        {
            var album = repository.GetAlbum(id);
            
            if (album != null)
                album.Likes++;

            repository.Save();

            return album.Likes;
        }

        [HttpPost]
        public int YaNoMeGusta(int id)
        {
            var album = repository.GetAlbum(id);

            if (album != null)
                album.Likes--;

            repository.Save();

            return album.Likes;
        }     
    }
}
